/**
 * Created by 66xiaoqu on 2015/10/26.
 */

var async = require('async');
var mysqlUtil = require('../../../common/utils/mysqlUtil');

exports.exchangeListService = function(req ,callback) {

    var body = req.body;
    var page = req.params.page;
    var size = Number(req.params.size);
    var index = (Number(req.params.page) - 1) * size;
    var totalPage = 0;


    var sql1 = "select count(*) as count from score_shop where 1 = 1";
    var sql2 = "select * from score_shop where 1 = 1 order by dateCreate desc limit " + index +"," + size;

   async.series([

       function(callbackInner) {

           mysqlUtil.query(sql1, function (err, result) {


               if (err || result.length == 0) {
                   callbackInner(err, null);
               }else {
                   var count = result[0].count;
                   var temp = {count: count, totalPage:Math.ceil(count/size)};
                   callbackInner(err, temp);
               }
           });
       },

       function(callbackInner) {
           mysqlUtil.query(sql2, function (err, result) {
               callbackInner(err, result);
           });
       },

   ], callback);


};